package weblab.tutor;

import utils.ExercisesTasks;
import utils.LessonsTasks;
import utils.QuizTasks;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

public class WebExercisesInterface {
	
    Context mContext;   
    String lesson_id = "";
    String exerciseFormat="";

    /** Instantiate the interface and set the context */
    WebExercisesInterface(Context c,String s, String text) {
        mContext = c;
        lesson_id = s;
        this.exerciseFormat = text;
    }

    /** Show a toast from the web page */
    //@JavascriptInterface
    
    public String getExercise() {
    	String text = "";
    	try{
    		Toast.makeText(mContext, "Retrieving exercise", Toast.LENGTH_SHORT).show();
    		text = new ExercisesTasks().execute("get_exercise",lesson_id, exerciseFormat).get();
    	}
    	catch(Exception e){
    		e.printStackTrace();
    	}
    	return text;
    }
    
    public String getContent() {
    	String text = "";
    	try{
    		Toast.makeText(mContext, "Retrieving data", Toast.LENGTH_SHORT).show();
    		text = new LessonsTasks().execute("get_content",lesson_id).get();
    	}
    	catch(Exception e){
    		e.printStackTrace();
    	}
    	return text;
    }
    
    public void redirect(String lesson_id){
    	Intent i = new Intent(mContext,LessonsActivity.class);
    	i.putExtra("lesson_id", lesson_id);
    	mContext.startActivity(i);
    }
    
    public void exercisesRedirect(){
    	Intent i = new Intent(mContext,QuizActivity.class);
    	i.putExtra("lesson_id", lesson_id);
    	mContext.startActivity(i);
    }
    
    public void quizRedirect(){
    	Intent i = new Intent(mContext,ExercisesActivity.class);
    	i.putExtra("lesson_id", lesson_id);
    	mContext.startActivity(i);
    }
}